package wickethub.web.page;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;

import wickethub.domain.Component;

public class ViewComponentPanel extends Panel {
	
	public ViewComponentPanel(String id, final IModel<Component> model) {
		super(id);
		
		add(new Label("license", new AbstractReadOnlyModel<String>() {
			@Override
			public String getObject() {
				if (model.getObject().getLicense() == null) {
					return getString("unknown");
				}
				return getString(model.getObject().getLicense().name());
			}
		}));
		
		String websiteUrl = model.getObject().getWebsiteUrl();
		String examplesUrl = model.getObject().getExamplesUrl();
		String jarUrl = model.getObject().getJarUrl();
		
		ExternalLink websiteLink = new ExternalLink("websiteLink", websiteUrl);
		websiteLink.add(new Label("websiteUrl", websiteUrl));
		websiteLink.setVisible(websiteUrl != null);
		add(websiteLink);
		
		ExternalLink examplesLink = new ExternalLink("examplesLink", examplesUrl);
		examplesLink.add(new Label("examplesUrl", examplesUrl));
		examplesLink.setVisible(examplesUrl != null);
		add(examplesLink);
		
		ExternalLink jarLink = new ExternalLink("jarLink", jarUrl);
		jarLink.add(new Label("jarUrl", jarUrl));
		jarLink.setVisible(jarUrl != null);
		add(jarLink);
		
    }
    
}